﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SEO.Business;

/// <summary>
/// 抓虫运行情况
/// </summary>
public partial class SysRunLogList : AdminPage
{
    /// <summary>
    /// 开始时间
    /// </summary>
    protected string BeginDateTime
    {
        get { return ViewState["BeginDateTime"] == null ? "" : ViewState["BeginDateTime"].ToString(); }
        set { ViewState["BeginDateTime"] = value; }
    }

    /// <summary>
    /// 结束时间
    /// </summary>
    protected string EndDateTime
    {
        get { return ViewState["EndDateTime"] == null ? "" : ViewState["EndDateTime"].ToString(); }
        set { ViewState["EndDateTime"] = value; }
    }

    protected int nNum = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitData();
        }
    }

    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="src"></param>
    /// <param name="e"></param>
    protected void anpPage_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        anpPage.CurrentPageIndex = e.NewPageIndex;
        InitData();
    }

    /// <summary>
    /// 权限控制
    /// </summary>
    /// <returns></returns>
    public override long GetNeededFeatures()
    {
        return AdminFEATURE.SysRunLogList;
    }

    /// <summary>
    /// 初始化数据
    /// </summary>
    protected void InitData()
    {
        int nRecordCount = 0;
        int nPageCount = 0;
        DateTime dBeginTime = Convert.ToDateTime("1753-01-01 12:00:00");
        DateTime dEndTime = Convert.ToDateTime("9999-12-31 11:59:59");
        if (!string.IsNullOrEmpty(BeginDateTime))
        {
            dBeginTime = Convert.ToDateTime(BeginDateTime);

        }
        if (!string.IsNullOrEmpty(EndDateTime))
        {
            dEndTime = Convert.ToDateTime(EndDateTime);
            dEndTime = dEndTime.AddDays(1);
        }
        //信息列表绑定
        DataTable dt = new BisSysRunLog().GetList(dBeginTime,dEndTime, anpPage.CurrentPageIndex, anpPage.PageSize, ref nPageCount, ref nRecordCount);
        anpPage.RecordCount = nRecordCount;
        nNum = (anpPage.CurrentPageIndex - 1) * anpPage.PageSize;
        nNum++;
        anpPage.RecordCount = nRecordCount;
        if (nRecordCount == 0)
        {
            noData.Style["display"] = "block";
        }
        else
        {
            noData.Style["display"] = "none";
        }
        rptSysRunLog.DataSource = dt;
        rptSysRunLog.DataBind();
        dt.Dispose();

        anpPage.CustomInfoHTML = string.Format("<div class=\"pagetag\">当前第<b>{0}</b>/<b>{1}</b>页 共<b>{2}</b>条记录</div>", new object[] { anpPage.CurrentPageIndex, anpPage.PageCount, anpPage.RecordCount });
    }

    /// <summary>
    /// 计算时间
    /// </summary>
    /// <param name="strBeginTime"></param>
    /// <param name="strEndTime"></param>
    /// <returns></returns>
    protected string CountTime(string strBeginTime, string strEndTime)
    {
        if (string.IsNullOrEmpty(strEndTime))
            return "";
        DateTime dBeginTime = Convert.ToDateTime(strBeginTime.Trim());
        DateTime dEndTime = Convert.ToDateTime(strEndTime.Trim());
        double dTime = 0;
        if (dEndTime > dBeginTime)
        {
            TimeSpan tsCount=dEndTime-dBeginTime;
            dTime = Convert.ToDouble(tsCount.TotalMinutes.ToString("0.##"));
        }
        if (dTime == 0)
            return "";
        //if (dTime >= 60)
        //{
        //    return Convert.ToInt32(dTime / 60).ToString() + "小时" + ((dTime % 60) > 0 ? ((dTime % 60).ToString() + "分钟") : "");
        //}
        //else
        //{
            return dTime.ToString() + "分钟";
        //}
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        
        BeginDateTime = txtBeginDateTime.Text.Trim();
        EndDateTime = txtEndDateTime.Text.Trim();
        anpPage.CurrentPageIndex = 1;
    }
}